<?php
// Main index
class TableAction extends CommonHomeAction {
    const STATE_OPEN = 0;
    const STATE_BEGIN = 1;
    const STATE_ORDER = 2;
    public function index() {
        $company_id = 1;

        $name = $this->_getDBName();
        $model = D($name);
        $voList = $model->where(array("company_id" => $company_id))->select();
        foreach ($voList as $k=>&$row) {
            $id = $row['id'];
            switch ($row['state'])
            {
                case 0:
                    $row['state_url'] = __GROUP__."/Table/begin/id/$id";
                    break;
                case 1:
                    $row['state_css'] = "ui-icon-bg";
                    $row['state_url'] = __GROUP__."/Table/order/id/$id";
                    break;
                default:
                    $row['state_css'] = "ui-icon-bg";                    
                    $row['state_url'] = "#";
                    break;
            }
        }
        if (false !== $list) {
            $this->assign("list", $voList);
        }
        $this->display();
    }
    
    public function begin() {
        $vo = $this->_update();
        if (!$vo) {
            $this->error("桌号不存在");
        }
        
        $this->assign('vo', $vo);
        $this->display();
    }
    
    public function order() {
       if ($this->isPost()) {
            // 提交的请求
            $name = $this->_getDBName();
            $model = D($name);
            $data = $model->create();
            $data['state'] = self::STATE_BEGIN;
            $model->save($data);
        }
        
        // Table
        $vo = $this->_update();
        if (!$vo) {
            $this->error("桌号不存在");
        }
        
        $this->assign('vo', $vo);
        
        // Menu
        $company_id = 1;
        $model = D("GoodsSort");
        $voList = $model->relation(true)->where(array("company_id" => $company_id))->select();
        $this->assign('list', $voList);    
        $this->display();
    }
}
?>
